package com.mdlaser.check;

import jakarta.annotation.PostConstruct;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.sql.SQLException;

@Configuration
@EnableCaching
@Log4j2
public class DataSourceCheck {


    @Autowired
    DataSource dataSource;

    @PostConstruct
    public void  checkDataSource() throws SQLException {
        try {
            dataSource.getConnection();
        } catch (SQLException e) {
            log.error("数据库连接失败，请检查数据库连接信息!");
            throw new SQLException(e);
        }
    }


}


